from matplotlib import pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei'] #决定中文显示问题设置字体为黑体
city = ['温州', '宁波', '杭州', '台州', '金华', '嘉兴', '绍兴', '湖州', '船山']
plt.title('浙江各省市的确诊人数和治愈人数对比')
p1 = [37, 11, 6, 26, 1, 4, 4, 8, 0]
p2 = [46, 158, 151, 120, 54, 41, 38, 17, 10]
bar_width = 0.4

plt.bar(range(len(city)), p1, color='steelblue', width=bar_width, label='确诊人数')
plt.bar(np.arange(len(city)) + bar_width + 0.005, p2, color='indianred', width=bar_width, label='治愈人数')

for x,y in enumerate(p1):
    plt.text(x, y + 5, str(y), ha='center', va='bottom')
for x,y in enumerate(p2):
    plt.text(x + bar_width + 0.005, y + 5, str(y), ha='center', va='bottom')
plt.xticks(np.arange(len(city)) + (bar_width + 0.005)/2, city)
#显示图例
plt.legend()
plt.show()
